package com.ruoyi.business.controller;

import com.ruoyi.business.domain.FileIntranetExport;
import com.ruoyi.business.domain.vo.FileIntranetExportVo;
import com.ruoyi.business.namage.FileExportManager;
import com.ruoyi.business.service.IFileIntranetExportService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 内网导出Controller
 *
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/business/export")
public class FileIntranetExportController extends BaseController
{
    @Autowired
    private IFileIntranetExportService fileIntranetExportService;

    @Autowired
    private FileExportManager exportManager;
    /**
     * 查询内网导出列表
     */
    @PreAuthorize("@ss.hasPermi('business:export:list')")
    @GetMapping("/list")
    public TableDataInfo list(FileIntranetExportVo fileIntranetExportVo, PageQuery pageQuery)
    {
        return fileIntranetExportService.selectPageFileIntranetExportList(fileIntranetExportVo,pageQuery);
//        startPage();
//        List<FileIntranetExport> list = fileIntranetExportService.selectFileIntranetExportList(fileIntranetExport);
//        return getDataTable(list);
    }

    /**
     * 导出内网导出列表
     */
    @PreAuthorize("@ss.hasPermi('business:export:export')")
    @Log(title = "内网导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(FileIntranetExport fileIntranetExport, HttpServletResponse response)
    {
        List<FileIntranetExport> list = fileIntranetExportService.selectFileIntranetExportList(fileIntranetExport);
        ExcelUtil.exportExcel(list, "内网导出", FileIntranetExport.class, response);
//        ExcelUtil<FileIntranetExport> util = new ExcelUtil<FileIntranetExport>(FileIntranetExport.class);
//        return util.exportExcel(list, "export");
    }

    @PreAuthorize("@ss.hasPermi('business:export:add')")
    @Log(title = "内网导出发送至磁盘", businessType = BusinessType.OTHER)
    @PostMapping("/sendToDisk/{id}")
    public void sendToDisk(@PathVariable("id") Long id)
    {
        FileIntranetExport fileIntranetExport = fileIntranetExportService.selectFileIntranetExportById(id);//获取导出信息
        exportManager.intranetExport(fileIntranetExport);
    }

    /**
     * 获取内网导出详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:export:query')")
    @GetMapping(value = "/{id}")
    public R<FileIntranetExport> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(fileIntranetExportService.selectFileIntranetExportById(id));
    }

    /**
     * 新增内网导出
     */
    @PreAuthorize("@ss.hasPermi('business:export:add')")
    @Log(title = "内网导出", businessType = BusinessType.INSERT)
    @PostMapping
    public R<FileIntranetExport> add(@RequestBody FileIntranetExport fileIntranetExport)
    {
        return R.ok(fileIntranetExportService.insertFileIntranetExport(fileIntranetExport));
    }

    /**
     * 修改内网导出
     */
    @PreAuthorize("@ss.hasPermi('business:export:edit')")
    @Log(title = "内网导出", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<FileIntranetExport> edit(@RequestBody FileIntranetExport fileIntranetExport)
    {
        return R.ok(fileIntranetExportService.updateFileIntranetExport(fileIntranetExport));
    }

    /**
     * 删除内网导出
     */
    @PreAuthorize("@ss.hasPermi('business:export:remove')")
    @Log(title = "内网导出", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return toAjax(fileIntranetExportService.deleteFileIntranetExportByIds(ids));
    }
}
